package com.redis.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissionConfiguration {

//    @Value("${spring.redis.host}")
//    private String host; //192.168.221.37
//    @Value("${spring.redis.port}")
//    private String port;

    @Value("${spring.redis.cluster.nodes}")
    private  String nodes;


    @Bean
    public RedissonClient getRedisson(){
        Config config = new Config();
// //多节点config.useClusterServers()
        //单机模式  依次设置redis地址和密码
        // 不是集群模式  useSingleServer redis单体的
       for(String nodeAddress : nodes.split(",")){
           //192.168.221.37:7001
           //
           config.useClusterServers().addNodeAddress("redis://"+nodeAddress);
       }

        // redis://
//        config.useSingleServer().
//                setAddress("redis://"+host+":"+port);

        return Redisson.create(config);
    }
}
